﻿<controls:ChildWindow xmlns:my="clr-namespace:caedisi.Views.Controls"  x:Class="caedisi.Views.InverterParameters"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           MinWidth="800" MinHeight="600" 
           Title="New Cellular Automata Parameters" 
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           xmlns:Helpers="clr-namespace:caedisi.Helpers"
           DataContext="{Binding RelativeSource={RelativeSource Self}}"
                      
>
           
    <controls:ChildWindow.Resources>
        <Helpers:GlobalVariableProvider x:Key="GlobalVariableProvider" />
    </controls:ChildWindow.Resources>
    
    
    <Grid x:Name="LayoutRoot" Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <!--Grid content top-->
        <Grid Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" /> <!--Line 0 is title-->
                <RowDefinition Height="Auto"/> <!--Line 1 is properties-->
                <RowDefinition Height="*" /> <!--Line 2 is Transition rules-->
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>               
             </Grid.ColumnDefinitions>

            <!-- Neighbourhood column-->
            <sdk:Label Grid.Row="0" Grid.Column="0"  Content="Neighbourhood Definition" HorizontalAlignment="Left"  VerticalAlignment="Top" Margin="0,0,25,0" />

            <StackPanel Grid.Row="1" Grid.Column="0">
                <ComboBox  x:Name="comboBoxNeighbourhoodType"  MinWidth="150" Height="23" Margin="0,0,25,0" ItemsSource="{Binding Source={StaticResource GlobalVariableProvider}, Path=GlobalVariables.Lovs.NeighbourhoodTypes, Mode=TwoWay}" SelectedValuePath="NeighbourhoodTypeId" SelectedValue="{Binding Path=CurrentCellularAutomata.NeighbourhoodTypeId, Mode=TwoWay, NotifyOnValidationError=True}"  IsEnabled="{Binding Path=IsNeighbourhoodTypeEnabled, Mode=TwoWay}" VerticalAlignment="Top">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="0,3,0,3">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Path=Name}"/>                            
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>                
             </StackPanel>

            
            <!-- Topology column-->
            <sdk:Label Grid.Row="0" Grid.Column="1"   Content="Topology" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,25,0"/>
            <Grid  Grid.Row="1" Grid.Column="1" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <sdk:Label Grid.Row="0" Grid.Column="0"   Content="Width" HorizontalAlignment="Left" />
                <TextBox Grid.Row="0" Grid.Column="1" Height="23" HorizontalAlignment="Left"  Name="textBoxNumberOfRows" VerticalAlignment="Top" Width="40"  Text="{Binding Path=CurrentCellularAutomata.Width, Mode=TwoWay, NotifyOnValidationError=True}" IsEnabled="{Binding Path=IsNeighbourhoodTypeEnabled, Mode=TwoWay}"/>
                <sdk:Label Grid.Row="0" Grid.Column="2"   Content="Height" HorizontalAlignment="Left"  />
                <TextBox Grid.Row="0" Grid.Column="3" Height="23" HorizontalAlignment="Left"  Name="textBoxNumberOfColumns" VerticalAlignment="Top" Width="40" Margin="0,0,25,0" Text="{Binding Path=CurrentCellularAutomata.Height, Mode=TwoWay, NotifyOnValidationError=True}" IsEnabled="{Binding Path=IsNeighbourhoodTypeEnabled, Mode=TwoWay}"/>
                <CheckBox Grid.Row="1" Grid.ColumnSpan="4" Content="Circular Horizontal" IsChecked="{Binding Path=CurrentCellularAutomata.CircularHorizontal, Mode=TwoWay, NotifyOnValidationError=True}"/>
                <CheckBox Grid.Row="2" Grid.ColumnSpan="4" Content="Circular Vertical" IsChecked="{Binding Path=CurrentCellularAutomata.CircularVertical, Mode=TwoWay, NotifyOnValidationError=True}"/>

            </Grid>
            
            <!-- Name column-->            
            <sdk:Label Grid.Row="0" Grid.Column="2"  Content="Algorithm Name" HorizontalAlignment="Left"  VerticalAlignment="Top" Margin="0,0,25,0" />
            <TextBox  Grid.Row="1" Grid.Column="2"  HorizontalAlignment="Left" VerticalAlignment="Top" Width="200" Margin="0,0,25,0" Text="{Binding Path=CurrentCellularAutomata.Name, Mode=TwoWay, NotifyOnValidationError=True}"/>

            <!-- Description column-->
            <Grid Grid.Row="1" Grid.Column="2"  >
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <TextBox   HorizontalAlignment="Stretch" VerticalAlignment="Top"  Margin="0,0,25,0" Text="{Binding Path=CurrentCellularAutomata.Name, Mode=TwoWay, NotifyOnValidationError=True}"/>
                <!-- Description column-->
                <sdk:Label Grid.Row="1"  Content="Description" HorizontalAlignment="Left"  VerticalAlignment="Top"  Margin="0,0,25,0" />
                <TextBox AcceptsReturn="True"  Grid.Row="2"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"   Text="{Binding Path=CurrentCellularAutomata.Description, Mode=TwoWay, NotifyOnValidationError=True}" Margin="0,0,25,0" />
            </Grid>


            <!-- Miscaleneous column-->
            <sdk:Label Grid.Row="0" Grid.Column="3"   Content="Decontamination Properties" HorizontalAlignment="Left" VerticalAlignment="Top"/>

            <Grid Grid.Row="1" Grid.Column="3"  >
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
            </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
            <sdk:Label Grid.Row="0" Grid.Column="0"   Content="Immunity time" HorizontalAlignment="Left"  />
            <TextBox Grid.Row="0" Grid.Column="1" Height="23" HorizontalAlignment="Left"  Name="ImmunityTime" VerticalAlignment="Top" Width="30" Text="{Binding Path=CurrentCellularAutomata.ImmunityTime, Mode=TwoWay, NotifyOnValidationError=True}" />
            <sdk:Label Grid.Row="1" Grid.Column="0"   Content="Visibility Radius" HorizontalAlignment="Left"  />
                <TextBox Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left"  Name="RadiusVisibility" Width="30" Text="{Binding Path=CurrentCellularAutomata.RadiusVisibility, Mode=TwoWay, NotifyOnValidationError=True}" IsEnabled="{Binding Path=IsNeighbourhoodTypeEnabled, Mode=TwoWay}"/>
            <sdk:Label Grid.Row="2" Content="Contamination distance" HorizontalAlignment="Left" Height="23" VerticalAlignment="Top" />
                <TextBox Grid.Row="2" Grid.Column="1" Height="23" HorizontalAlignment="Left"  Name="RadiusContamination" VerticalAlignment="Top" Width="30" Text="{Binding Path=CurrentCellularAutomata.RadiusContamination, Mode=TwoWay, NotifyOnValidationError=True}"  IsEnabled="{Binding Path=IsNeighbourhoodTypeEnabled, Mode=TwoWay}"/>
         </Grid>
                                       
            <!--Rules Dynamic rows-->
            <Grid Grid.Row="2" Grid.ColumnSpan="5">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <sdk:Label Content="Transition Rules" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,25,0"/>

                <CheckBox Grid.Row="1" x:Name="checkBoxAutoCleanInNextStep" Content="automatically set decontaminating cell to decontaminated in next step" IsChecked="{Binding Path=CurrentInverterExecution.IsDecontaminatingCleanInNextStep, Mode=TwoWay}" IsEnabled="{Binding Path=IsNeighbourhoodTypeEnabled, Mode=TwoWay}" VerticalContentAlignment="Center"  />
                                                                                 
                
                <ScrollViewer Name="rules" Grid.Row="2" VerticalScrollBarVisibility="Visible" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch">
                    <ListBox  x:Name="stackOfRules"  ItemsSource="{Binding Path=CurrentCellularAutomata.TransitionRules}"  HorizontalAlignment="Stretch" SelectionChanged="stackOfRules_SelectionChanged" HorizontalContentAlignment="Stretch" MinHeight="200">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Button Content="Remove" Click="ButtonRemoveTransitionRule_Click" Height="23" VerticalAlignment="Top" CommandParameter="{Binding}"/>
                                    <my:TransitionRuleControl CurrentTransitionRule="{Binding }" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"/>
                                </StackPanel>                                    
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </ScrollViewer>
             </Grid>

        </Grid>

        <!--Grid buttons-->
        <StackPanel Grid.Row="1" Orientation="Horizontal" FlowDirection="RightToLeft">           
            <Button x:Name="OKButton" Content="Ok" Click="ButtonValidateAndAcceptButton_Click" Width="75" Height="23" HorizontalAlignment="Right"   />
            <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Height="23" Width="75" HorizontalAlignment="Right"  />
        </StackPanel>
    </Grid>
</controls:ChildWindow>